package com.androidx.p013lv.mine.activity;

import android.graphics.Bitmap;
import android.os.Build;
import android.text.TextUtils;
import android.widget.TextView;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.DeviceIDUtils;
import com.androidx.p013lv.base.utils.ImageUtil;
import com.androidx.p013lv.base.utils.QRCodeUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.bean.ShareLinkBean;
import com.androidx.p013lv.mine.databinding.ActivityAccountCredentialsLayoutBinding;
import com.gyf.immersionbar.ImmersionBar;
import com.lzy.okgo.model.Response;
import org.slf4j.Marker;
import p000a.p002b.RxPermissions;
import p023io.reactivex.functions.Consumer;

/* renamed from: com.androidx.lv.mine.activity.AccountCredentialsActivity */
public class AccountCredentialsActivity extends BaseActivity<ActivityAccountCredentialsLayoutBinding> {
    public String title;
    public int type;

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityAccountCredentialsLayoutBinding) this.binding).toolbar).init();
    }

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return C1207R.C1212layout.activity_account_credentials_layout;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        ((ActivityAccountCredentialsLayoutBinding) this.binding).setClick(new OnClick());
        ((ActivityAccountCredentialsLayoutBinding) this.binding).setTitle(this.title);
        UserInfo userInfo = SpUtils.getInstance().getUserInfo();
        String uniqueId = DeviceIDUtils.getUniqueId(this);
        ((ActivityAccountCredentialsLayoutBinding) this.binding).f326a.setImageBitmap(QRCodeUtil.createQRCode(uniqueId + Marker.ANY_MARKER + userInfo.getUserId(), 400));
        ((ActivityAccountCredentialsLayoutBinding) this.binding).ivTitle.setImageResource(C1207R.C1209drawable.bg_acc_credentials_top);
        getShareLink();
    }

    public void getShareLink() {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().ShareLink(), new HttpCallback<BaseRes<ShareLinkBean>>("ShareLink") {
            /* class com.androidx.p013lv.mine.activity.AccountCredentialsActivity.C12161 */

            public void onLvSuccess(BaseRes<ShareLinkBean> baseRes) {
            }

            @Override // com.androidx.p013lv.base.http.callback.HttpCallback, com.lzy.okgo.callback.Callback
            public void onSuccess(Response<BaseRes<ShareLinkBean>> response) {
                if (200 == response.body().getCode() && !TextUtils.isEmpty(response.body().getData().getUrl())) {
                    TextView textView = ((ActivityAccountCredentialsLayoutBinding) AccountCredentialsActivity.this.binding).tvUrl;
                    textView.setText(response.body().getData().getUrl() + "");
                }
            }

            @Override // com.androidx.p013lv.base.http.callback.HttpCallback, com.lzy.okgo.callback.AbsCallback, com.lzy.okgo.callback.Callback
            public void onError(Response<BaseRes<ShareLinkBean>> response) {
                super.onError(response);
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void requestPermission(final Bitmap bitmap) {
        if (Build.VERSION.SDK_INT >= 23) {
            new RxPermissions(this).request("android.permission.WRITE_EXTERNAL_STORAGE").subscribe(new Consumer<Boolean>() {
                /* class com.androidx.p013lv.mine.activity.AccountCredentialsActivity.C12172 */

                public void accept(Boolean bool) throws Exception {
                    if (bool.booleanValue()) {
                        ImageUtil.saveImageToGallery(AccountCredentialsActivity.this.getActivity(), bitmap);
                    } else {
                        ToastUtils.getInstance().showSigh("未授權權限，請在設置中允許權限");
                    }
                }
            });
        } else {
            ImageUtil.saveImageToGallery(getActivity(), bitmap);
        }
    }

    /* renamed from: com.androidx.lv.mine.activity.AccountCredentialsActivity$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void btnBack() {
            SpUtils.getInstance().put(Key.TIME, System.currentTimeMillis());
            if (AccountCredentialsActivity.this.type == 1) {
                ARouter.getInstance().build(Constance.MAIN_ACTIVITY).navigation();
            }
            AccountCredentialsActivity.this.finish();
        }

        public void saveAccCredentials() {
            SpUtils.getInstance().put("status", 1);
            AccountCredentialsActivity accountCredentialsActivity = AccountCredentialsActivity.this;
            accountCredentialsActivity.requestPermission(QRCodeUtil.loadBitmapFromView(((ActivityAccountCredentialsLayoutBinding) accountCredentialsActivity.binding).rootView, ((ActivityAccountCredentialsLayoutBinding) AccountCredentialsActivity.this.binding).rootView.getHeight()));
            if (AccountCredentialsActivity.this.type == 1) {
                ARouter.getInstance().build(Constance.MAIN_ACTIVITY).navigation();
                AccountCredentialsActivity.this.finish();
            }
        }
    }
}
